const userModule = require('../albx_modules/userModule')
module.exports = {
    login(req, res) {
        let obj = req.body;
        userModule.userLogin(obj.email, (err, data) => {
            if (err) return res.json({
                code: '400',
                msg: '服务器异常'
            })
            if (data) {
                if (obj.password === data.password) {
                    req.session.isLogin = 'true';
                    req.session.userId = data.id;
                    res.json({
                        code: '200',
                        msg: '登陆成功'
                    })
                    // console.log( req.session.isLogin,req.session.userId)
                } else {
                    res.json({
                        code: '201',
                        msg: '密码错误'
                    })
                }
            } else {
                res.json({
                    code: '201',
                    msg: '邮箱输入错误'
                })
            }
        })
    },
    loginOut(req,res){
        req.session.isLogin='';
        res.json({
            code:'200',
            msg:"退出成功"
        })
    }
}